
let obj = {
    name: 'ljp',
    add(a, b) {
        console.log(this.name, a, b)
    }
}

const obj1 = {
    name: 'xxx'
}

obj.add(1, 2)

obj.add.apply(obj1, [1, 2])

Function.prototype.myApply = function (ctx, args) {
    let res;
    if (typeof this === 'function') {
        ctx.fn = this
        res = ctx.fn(...args)
    }
    delete ctx.fn
    return res
}


obj.add.myApply(obj1, [1, 2])


/***
 *  将call传入的ctx作为原型 
 *  将实例（this）挂在ctx上
 *  执行ctx.fn  将ctx.fn执行结果返回  
 *  并还原ctx 即 删除ctx.fn
 * 
 */